// 监听来自content script的消息
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  if (request.type === 'captureVisible') {
    chrome.tabs.captureVisibleTab(null, {format: 'png'})
      .then(dataUrl => {
        sendResponse({dataUrl});
      })
      .catch(error => {
        console.error('Screenshot error:', error);
        sendResponse({error: error.message});
      });
    return true; // 表示将异步发送响应
  }

  if (request.type === 'contentScriptReady') {
    console.log('Content script is ready');
    return false;
  }
});

// 当扩展安装或更新时初始化
chrome.runtime.onInstalled.addListener(() => {
  console.log('Extension installed/updated');
});

